# Author: Yu Bin
# Date: 2024/12/27 08:55:51
# E-mail: 853823259@qq.com

# 元组
info_tuple = ("zhangsan", 18, 1.75)
print(info_tuple[0])

for i in info_tuple:
    print(i)
print(info_tuple.count("zhangsan"))

print("%s的年龄是%d，身高是%.2f" % info_tuple)

# 字典
xiaoming_dict = {"name": "小明"}
# 1.取值
print(xiaoming_dict['name'])
# 2.增加、修改
xiaoming_dict['age'] = 18
print(xiaoming_dict)
xiaoming_dict['name'] = '小小明'
print(xiaoming_dict)
# 3.删除
print(xiaoming_dict.pop('name'))
print(xiaoming_dict)
# 4.统计
print(len(xiaoming_dict))
# 5.合并字典
temp_dict = {'height': 1.75,
             'age': 20}
xiaoming_dict.update(temp_dict)
print(xiaoming_dict)
# 6.清空
# xiaoming_dict.clear()
# print(xiaoming_dict)
# print(id(xiaoming_dict))
# 7.遍历
for k in xiaoming_dict:
    print(k, xiaoming_dict[k])
for k in xiaoming_dict:
    print("%s-%s" % (k, xiaoming_dict[k]))
card_list = [
    {"name": "张三",
     "qq": "12345",
     "phone": "110"},
    {"name": "李四",
     "qq": "54321",
     "phone": "10086"}
]
for card_info in card_list:
    print(card_info)

# 字符串
# 1.遍历
str1 = "Hello Python"
for c in str1:
    print(c)

num_str = "0123456789"
# 1. 截取从 2 ~ 5 位置 的字符串
print(num_str[2:6])
# 2. 截取从 2 ~ `末尾` 的字符串
print(num_str[2:])
# 3. 截取从 `开始` ~ 5 位置 的字符串
print(num_str[:6])
# 4. 截取完整的字符串
print(num_str[:])
# 5. 从开始位置， 每隔一个字符截取字符串
print(num_str[::2])
# 6. 从索引 1 开始， 每隔一个取一个
print(num_str[1::2])
# 倒序切片
# -1 表示倒数第一个字符
print(num_str[-1])
# 7. 截取从 2 ~ `末尾 - 1` 的字符串
print(num_str[2:-1])
# 8. 截取字符串末尾两个字符
print(num_str[-2:])
# 9. 字符串的逆序（面试题）
print(num_str[::-1])

# 集合
demo_set = set()
print(type(demo_set))

fruits = {"apple", "banana", "cherry"}
print(fruits)
fruits.add("orange")
print(fruits)

# 复制
fruits = {"apple", "banana", "cherry"}
print(id(fruits))
x = fruits
print(id(x))
x = fruits.copy()
print(x)
print(id(x))

a = (1, 2, 3)
b = ('a', 'b', 'c')
print(list(zip(a, b)))
print(dict(zip(a, b)))

# 如何使用 enumerate
seasons = ['Spring', 'Summer', 'Fall', 'Winter']
list2 = list(enumerate(seasons))
print(list2)
dict1 = {}
for i in list2:
    dict1[i[1]] = i[0]
print(dict1)

# 1 有7个整数，其中有3个数出现了两次，1个数出现了一次， 找出出现了一次的那个数。
list1 = [1, 1, 2, 2, 3, 6, 6]
res = 0
for i in list1:
    res = res ^ i
print(res)

# 6 有8个整数，其中有4个数出现了两次，2个数出现了一次， 找出出现了一次的那2个数
list1 = [1, 1, 2, 2, 3, 6, 6, 8, 3, 9, 8, 10]
res = 0
res1 = 0
res2 = 0
for i in list1:
    res = res ^ i
res &= -res
for i in list1:
    if res & i:
        res1 ^= i
    else:
        res2 ^= i
print("%d %d" % (res1, res2))
